package com.yanqu.road.server.cmd.activity.xiaowurecall;

import com.yanqu.road.pb.activity.XiaowuRecallProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.xiaowuRecall.XiaowuRecallModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_XIAOWU_RECALL_GET_REWARD, desc = "小舞回忆录领奖请求")
public class GetRecallRewardCmd extends AbstractCommand {

    int activityId;
    int cellId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        XiaowuRecallProto.XiaowuGetRewardReqMsg reqMsg = XiaowuRecallProto.XiaowuGetRewardReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        cellId = reqMsg.getCellId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(XiaowuRecallModule.class).getReward(cellId);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            XiaowuRecallProto.XiaowuGetRewardRespMsg.Builder respMsg = XiaowuRecallProto.XiaowuGetRewardRespMsg.newBuilder();
            respMsg.setRet(ret);
            respMsg.setReward("");
            player.sendPacket(Protocol.U_XIAOWU_RECALL_GET_REWARD, respMsg);
        }
    }
}
